package com.dfbz.demo02_InputStream;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo04_读取一个字节数组 {
    public static void main(String[] args) throws Exception {

        InputStream is = new FileInputStream("001.txt");


        byte[] data = new byte[2];
        int len = is.read(data);
        System.out.println(Arrays.toString(data));                  // a b
        System.out.println("本次读取到的有效字节个数：" + len);          // 2

        len = is.read(data);
        System.out.println(Arrays.toString(data));                  // c d
        System.out.println("本次读取到的有效字节个数：" + len);          // 2

        len = is.read(data);
        System.out.println(Arrays.toString(data));                  // e(101) d(100)
        System.out.println("本次读取到的有效字节个数：" + len);          // 1

        len = is.read(data);
        System.out.println(Arrays.toString(data));                  // e(101) d(100)
        System.out.println("本次读取到的有效字节个数：" + len);          // -1


        is.close();

    }
}
